package T13;

import java.util.*;
public class Test2{
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder s = new StringBuilder(sc.nextLine());
        char[] t = sc.nextLine().toCharArray();
        int len = s.length();
        int flag = 0;
        int len1 = t.length;
        int index = 0;//代表光标的位置
        for(int i = 0;i < len1;i ++){
            if(flag == 0){
                //不录入字母
                if(t[i] == 'i'){
                    flag = 1;
                }else if(t[i] == 'f'){
                    int next = i + 1;
                    if(next < len1){
                        i ++;
                        char ch = t[next];
                        for(int j = index + 1;j < len;j ++){
                            if(s.charAt(j) == ch){
                                index = j;
                                break;
                            }
                        }
                    }

                }else if(t[i] == 'x'){
                    s.deleteCharAt(index);
                    len = s.length();

                }else if(t[i] == 'h'){
                    if(index != 0) index --;
                }else if(t[i] == 'l'){
                    if(index != len - 1) index ++;
                }
            }else{
                if(t[i] == 'e'){
                    flag = 0;
                }else{
                    s.insert(index,t[i]);
                    len = s.length();
                    index ++;
                }
            }
        }
        System.out.println(s.toString());

    }
}
